import * as Cesium from 'cesium/Cesium';
import ImageryFactory from "../../src/imagery/ImageryFactory.js";


/**
 * 添加底图数据
 * @param {} earth 
 */
 export default function addBaseLayers(earth){
    /** 创建ArcGIS图层 */
    add_arcgis_imagery(earth);

    /** 创建WMS图层 */
    //add_wms_imagery(earth);

    //add_wmts_imagery(earth);
}

/**
 * 创建ArcGIS图层
 */
function add_arcgis_imagery(earth){    
    let provider = ImageryFactory.createArcGISImageryProvider();
    earth.addBaseLayer(provider);
}

/** 
 * 创建WMS图层 
 * 代理：代理到geoserver
 * */
function add_wms_imagery(earth){
    let options = {
        url : '/geoserver/radi/wms',
        layers : 'radi:china'        
    };

    let provider = ImageryFactory.createWebMapServiceImageryProvider(options);
    earth.addBaseLayer(provider);


    earth.zoomToPosition({
        lng:116, lat:39.0, alt:10000000.0
    });
}

// function add_wmts_imagery(earth){
//     let options = {
//         url : 'http://basemap.nationalmap.gov/arcgis/rest/services/USGSShadedReliefOnly/MapServer/WMTS',
//         layer : 'USGSShadedReliefOnly',
//         style : 'default',
//         format : 'image/jpeg',
//         tileMatrixSetID : 'default028mm',
//         // tileMatrixLabels : ['default028mm:0', 'default028mm:1', 'default028mm:2' ...],
//         maximumLevel: 19,
//         credit : new Cesium.Credit('U. S. Geological Survey')
//     };

//     let provider = ImageryFactory.createWebMapTileServiceImageryProvider(options);
//     earth.addBaseLayer(provider);

// }

function add_wmts_imagery(earth){
    //url : 'http://127.0.0.1/geoserver/gwc/service/wmts/rest/radi:cities/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/png',
    let options = {
        url : '/geoserver/gwc/service/wmts',
        layer : 'radi:country',
        style : 'polygon',
        format : 'image/png',
        tileMatrixSetID : 'EPSG:4326',
        tilingScheme : new Cesium.GeographicTilingScheme(),
        tileMatrixLabels : ['EPSG:4326:0', 'EPSG:4326:1', 'EPSG:4326:2', 'EPSG:4326:3', 'EPSG:4326:4', 'EPSG:4326:5', 'EPSG:4326:6', 'EPSG:4326:7', 'EPSG:4326:8', 'EPSG:4326:9', 'EPSG:4326:10', 'EPSG:4326:11', 'EPSG:4326:12', 'EPSG:4326:13', 'EPSG:4326:14', 'EPSG:4326:15', 'EPSG:4326:16', 'EPSG:4326:17'],
        maximumLevel: 18,
    };

    let provider = ImageryFactory.createWebMapTileServiceImageryProvider(options);
    earth.addBaseLayer(provider);

}

